package com.buyhouse.zhaimao.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.buyhouse.zhaimao.BaseFragment;
import com.buyhouse.zhaimao.R;
import com.buyhouse.zhaimao.model.TimelineBean;
import com.buyhouse.zhaimao.view.CircleImageView;

/**
 * 日期管理
 * 
 * @author
 *
 */
public class ManagementFragment extends BaseFragment {
	private TextView month, date;
	private ListView schedule_listview;
	private ManagementAdapter mAdapter;
	private List<TimelineBean> list = new ArrayList<TimelineBean>();
	@Override
	protected int getContentView() {
		return R.layout.fragment_schedule_management;
	}

	@Override
	protected void initFragment() {
		 initData();
		 initView();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.month:

			break;
		case R.id.date:

			break;

		default:
			break;
		}
	}

	protected void initView() {
		month = (TextView) rootView.findViewById(R.id.month);
		date = (TextView) rootView.findViewById(R.id.date);
		date.setOnClickListener(this);
		month.setOnClickListener(this);
		schedule_listview=(ListView) rootView.findViewById(R.id.schedule_listview);
		mAdapter = new ManagementAdapter();
		schedule_listview.setAdapter(mAdapter);
	}
	
	protected void initData() {
		for(int i = 0 ; i<=5; i++){
			TimelineBean timelinebean = new TimelineBean();
			timelinebean.setDate("25");
			timelinebean.setInfo("与xxxxx内容xxxxxxxx");
			timelinebean.setListStatus("[待审核]");
			timelinebean.setMonth("12");
			timelinebean.setTime("9:24");
			timelinebean.setTitle("洽谈洽谈");
			timelinebean.setLink("www.baidu.com");
			list.add(timelinebean);
		}
		TimelineBean timelinebean = new TimelineBean();
		timelinebean.setDate("25");
		timelinebean.setInfo("与xxxxx内容xxxxxxxx与xxxxx内容xxxxxxxx与xxxxx内容xxxxxxxx与xxxxx内容xxxxxxxx与xxxxx内容xxxxxxxx");
		timelinebean.setListStatus("[待审核]");
		timelinebean.setMonth("12");
		timelinebean.setTime("9:24");
		timelinebean.setTitle("洽谈洽谈");
		list.add(timelinebean);
		
	}
	
	/**Adapter*/
	class ManagementAdapter extends BaseAdapter{
//		Context context;
		LayoutInflater inflater;
		
		public ManagementAdapter() {
			inflater = LayoutInflater.from(getActivity());
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder vh = null;
			if(null == convertView){
				convertView = inflater.inflate(R.layout.item_managementfragment, parent, false);
				
				vh = new ViewHolder();
				
				vh.circleImageView = (CircleImageView)convertView.findViewById(R.id.circleImageView);
				vh.title = (TextView)convertView.findViewById(R.id.title);
				vh.listStatus = (TextView)convertView.findViewById(R.id.listStatus);
				vh.info = (TextView)convertView.findViewById(R.id.info);
				vh.link = (LinearLayout)convertView.findViewById(R.id.link);
				vh.time = (TextView)convertView.findViewById(R.id.time);
				
				//把ViewHolder当作“标记”保存到当前的选项视图实例中
				convertView.setTag(vh);
			}else{
				vh = (ViewHolder)convertView.getTag();
			}
			TimelineBean  bean = list.get(position);
			vh.title.setText(bean.getTitle());
			vh.listStatus.setText(bean.getListStatus());
			vh.info.setText(bean.getInfo());
			vh.time.setText(bean.getTime());
//			Log.e("bean.getLink()", bean.getLink());
//			if(!bean.getLink().equals("")){
//				vh.link.setOnClickListener(new OnClickListener() {
//					
//					@Override
//					public void onClick(View v) {
//						Toast.makeText(getActivity(), "进链接", 2000).show();
//						
//					}
//				});
//			}else{
//				vh.link.setVisibility(View.GONE);
//			}
			
			
			return convertView;
		}
		
	}
	private class ViewHolder{
		CircleImageView circleImageView;
		TextView title,listStatus,tv_summary,info,time;
		LinearLayout link;
	}
}
